package com.icss.controller;

import com.icss.dao.IGoodDao;
import com.icss.entity.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class GoodController {
    @Autowired
    private IGoodDao iGoodDao;

//    查找所有商品
    @RequestMapping("findAllGoods")
    public  String  GoodFun01(HttpSession session){
        List<Goods> goodsList = iGoodDao.goodList();
        session.setAttribute("goodsList",goodsList);
        System.out.println(goodsList);
        return  "good";

    }
    @RequestMapping("findAllGoodsByKind")
    public  String  GoodFun02(String kind,HttpSession session){
        session.removeAttribute("goodsList");
        List<Goods> goodsList = iGoodDao.goodListByKind(kind);
        System.out.println(goodsList);
        session.setAttribute("goodsList",goodsList);
        return  "good";
    }
    @RequestMapping("findGoodById")
    public  String  GoodFun03(int goodsid,HttpSession session){
        Goods goods = iGoodDao.findGoodById(goodsid);
        session.setAttribute("goods",goods);
        return "goodinfo";
    }

}

